package com.sy.config;



import com.sy.demo.Cat;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

@Configuration
@ComponentScan("com.sy")
@Import(MainConfig.MyImportBeanDefinitionRegistrar.class)
public class MainConfig {


	/**
	 * 自定义注册BeanDefinition
	 * BeanDefinitionRegistrar：BeanDefinition的注册中心
	 * 使用静态内部类
	 */
	static class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {


		@Override
		public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
											BeanDefinitionRegistry registry) {

			RootBeanDefinition rootBeanDefinition = new RootBeanDefinition();
			rootBeanDefinition.setBeanClass(Cat.class);
			registry.registerBeanDefinition("cat", rootBeanDefinition);

		}

	}

}
